package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.utils.AliOssUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

/**
 * @projectName: HF62sky
 * @package: com.sky.controller.admin
 * @className: ConmonController
 * @author: SunGang
 * @description: TODO
 * @date: 2023/12/5 11:44
 * @version: 1.0
 */
@RestController
@RequestMapping("/admin/common")
@RequiredArgsConstructor
@Slf4j
public class ConmonController {
    private final AliOssUtil  aliOssUtil;
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file){
        try {
            String filename2 = file.getOriginalFilename(); //2.jpg
            String s = UUID.randomUUID() + filename2.substring(filename2.lastIndexOf("."));
            String url = aliOssUtil.upload(file.getBytes(), s);
            return Result.success(url);

        } catch (IOException e) {
           log.info("--------------文件上传失败----------------");
        }
        return Result.error("文件上传失败");
    }
}
